package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingProjectVo;
import com.zzyl.base.ResponseResult;
import com.zzyl.service.NursingLevelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursingLevel")
@Slf4j
@Api(tags = "服务项目管理相关接口")
public class NursingLevelController extends BaseController {

   @Autowired
    NursingLevelService nursingLevelService;

   //查询所有护理等级
   @GetMapping("/listAll")
   @ApiOperation("查询所有护理等级")
   public ResponseResult<List<NursingLevelVo>> nursingLevelList() {
       List<NursingLevelVo> nursingLevelVos = nursingLevelService.nursingLevelList();

       return success(nursingLevelVos);
   }
    //分页条件查询护理等级2
    @GetMapping("/listByPage")
    @ApiOperation("分页条件查询护理等级")
    public ResponseResult<PageResponse<NursingLevelVo>> selectByPage(
            @ApiParam(value = "护理等级名称")  String name,
            @ApiParam(value = "状态：0-禁用，1-启用") Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        log.info("分页查询护理等级列表：name={}, status={}, pageNum={}, pageSize={}", name, status, pageNum, pageSize);
        PageResponse<NursingLevelVo> pageInfo = nursingLevelService.selectByPage(pageNum, pageSize, name, status);
        return success(pageInfo);
    }

    //新增
    //新增护理项目
    @PostMapping("/insert")
    @ApiOperation("新增护理等级")
    public ResponseResult addNursingLevelDto(@ApiParam(value = "护理项目信息") @RequestBody NursingLevelDto nursingLevelDto){

        log.info("新增护理项目：{}", nursingLevelDto);
        nursingLevelService.addNursingLevelDto(nursingLevelDto);
        return success();
    }

    //根据id回显
    @GetMapping("/{id}")
    @ApiOperation("根据ID查询护理等级")
    public ResponseResult<NursingLevelVo> getNursingLevelById(@ApiParam(value = "护理等级ID") @PathVariable Long id){
        log.info("根据ID查询护理等级：{}", id);
        NursingLevelVo nursingLevelVo = nursingLevelService.getNursingLevelById(id);
        return success(nursingLevelVo);
    }

    //修改
    @PutMapping("/update")
    @ApiOperation("修改护理等级")
    public ResponseResult updateNursingLevelDto(@ApiParam(value = "护理等级信息") @RequestBody NursingLevelDto nursingLevelDto){
        log.info("修改护理等级：{}", nursingLevelDto);
        nursingLevelService.updateNursingLevelDto(nursingLevelDto);
        return success();
    }


    //启用禁用
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("修改护理等级状态")
    public ResponseResult updateNursingLevelStatus(@ApiParam(value = "护理等级ID") @PathVariable Long id,
                                                   @ApiParam(value = "状态：0-禁用，1-启用") @PathVariable Integer status){
        log.info("修改护理等级状态：id={}, status={}", id, status);
        nursingLevelService.updateNursingLevelStatus(id, status);
        return success();
    }


//    接口地址:/nursingLevel/delete/{id}
//    请求方式:DELETE
    //删除服务等级
    @ApiOperation(value = "删除服务等级")
    @DeleteMapping("/delete/{id}")
    public ResponseResult delete(@ApiParam(value = "服务等级id",required = true) @PathVariable("id") Long id){
        log.info("删除服务等级,id:{}",id);
        nursingLevelService.delete(id);
        return success();
    }
}